import {
	observable,
	action
} from 'mobx';

export default class AuthorityStore {
	constructor(api) {
		this.api = api;
	}

	@observable hasRight = false;
	@observable loading = true;

	@action fetchAuthority = () => {
		return new Promise((resolve, reject) => {
			this.api().then(datas => {
				const {
					hasRight
				} = datas;

				this.hasRight = hasRight;
				this.loading = false;

				if (hasRight) {
					resolve();
				}
			});
		})
	}
}